package xyz.jcat.shardingjdbc.example.domain.hint;

import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.api.sharding.hint.HintShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.hint.HintShardingValue;

import java.util.ArrayList;
import java.util.Collection;

@Slf4j
public class UserHintAlgorithm implements HintShardingAlgorithm<Integer> {
    @Override
    public Collection<String> doSharding(Collection<String> collection, HintShardingValue<Integer> hintShardingValue) {
        log.info("come in, hint ...");
        Collection<String> result = new ArrayList<>();
        collection.forEach(ds -> {
            for(Integer value : hintShardingValue.getValues()) {
                if(ds.endsWith(String.valueOf(value))) {
                    result.add(ds);
                }
            }
        });
        return result;
    }
}
